package com.onesports.intelligent.k12.polarlight.controller.operation.course;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.common.BasePageDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.course.CourseScheduleTemplateDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.CourseScheduleTemplateVO;
import com.onesports.intelligent.k12.polarlight.service.course.CourseScheduleTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author FPH
 * @since 2022年7月12日10:05:14
 */
@RestController
@RequestMapping(ApiPathConstants.ORG_COURSE_TEMPLATE)
@RequiredArgsConstructor
@Api(tags = "运营端-系统设置-排班模板表")
@PreAuthorize("isAuthenticated()")
public class CourseScheduleTemplateController {

    private final CourseScheduleTemplateService courseScheduleTemplateService;

    @PostMapping("save-or-update")
    @ApiOperation("通用保存修改接口")
    public ResponseEntity<String> saveOrUpdate(@RequestBody @Valid CourseScheduleTemplateDTO dto){
        return courseScheduleTemplateService.saveOrUpdateDetail(dto)
                ? ResultUtil.success("操作成功")
                : ResultUtil.success("操作失败");
    }

    @PostMapping("remove")
    @ApiOperation("删除")
    public ResponseEntity<String> remove(String id){
        return courseScheduleTemplateService.deleteById(id)
                ? ResultUtil.success("删除成功")
                : ResultUtil.success("删除失败");
    }

    @PostMapping("list")
    @ApiOperation("分页列表")
    public ResponseEntity<IPage<CourseScheduleTemplateVO>> page(@Valid @RequestBody BasePageDTO dto){
        return ResultUtil.success(courseScheduleTemplateService.getPageDetail(dto.getPage(),dto.getRow()));
    }
}
